package ch.pizzapp.kurier;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.Trace;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringArrayRes;
import org.androidannotations.annotations.rest.RestService;
import org.apache.http.conn.util.InetAddressUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import ch.pizzapp.kurier.adapter.CategoryAdapter;
import ch.pizzapp.kurier.adapter.OrderAdapater;
import ch.pizzapp.kurier.client.InfoClient;
import ch.pizzapp.kurier.data.CategoryData;
import ch.pizzapp.kurier.data.CategoryResponceData;
import ch.pizzapp.kurier.data.GenarateItem;
import ch.pizzapp.kurier.data.InfoData;
import ch.pizzapp.kurier.data.OderResponce;
import ch.pizzapp.kurier.data.OrderItemData;
import ch.pizzapp.kurier.data.PlaceData;
import ch.pizzapp.kurier.data.ResponceData;
import ch.pizzapp.kurier.data.Size;
import ch.pizzapp.kurier.data.UserData;
import ch.pizzapp.kurier.data.UserResonce;
import ch.pizzapp.kurier.dto.InfoDto;
import ch.pizzapp.kurier.view.SelectCallCallBack;

import com.bugsense.trace.BugSenseHandler;
import com.roomorama.caldroid.CaldroidFragment;
import com.roomorama.caldroid.CaldroidListener;

@EActivity(R.layout.activity_drawer)
public class DrawerActivity extends ActionBarActivity {

	@ViewById(R.id.address1)
	TextView address1tv;

	@ViewById(R.id.opentime)
	TextView opentime;

	@ViewById(R.id.tel)
	TextView tel;

	@ViewById(R.id.categoryListView)
	ListView categoryListView;

	@ViewById(R.id.userListView)
	ListView userListView;

	@ViewById(R.id.listViewItems)
	ListView listViewItems;

	@Extra("ResponceData")
	ResponceData responceData;

	@ViewById(R.id.left_drawer)
	ScrollView leftDrawer;

	@ViewById(R.id.right_drawer)
	ScrollView rightDrawer;

	@ViewById(R.id.textViewTotal)
	TextView textViewTotal;

	@ViewById(R.id.textViewDate)
	TextView textViewDate;

	@ViewById(R.id.textViewPaymentMethod)
	TextView textViewPaymentMethod;

	@ViewById(R.id.textViewTime)
	TextView textViewTime;

	@ViewById(R.id.textViewMinimumOder)
	TextView textViewMinimumOder;

	@ViewById(R.id.textViewCreditMemo)
	TextView textViewCreditMemo;

	@ViewById(R.id.buttonCheckout)
	Button buttonCheckout;

	@Extra("UserResonce")
	UserResonce userResonce;

	@Extra("PlaceDataItem")
	PlaceData placeDataItemPar;

	@Bean
	CategoryAdapter userAdapter;

	@Bean
	InfoDto infoDto;

	@RestService
	InfoClient InfoClient;

	@Bean
	CategoryAdapter categoryAdapter;

	@Bean
	OrderAdapater orderAdapater;

	Double totalPrice = 0.0;

	@ViewById(R.id.login_status)
	protected LinearLayout mLoginStatusView;

	// List<OrderItemData> orderItemDataList = new ArrayList<OrderItemData>();
	List<OrderItemData> orderItemDataList = Collections
			.synchronizedList(new ArrayList<OrderItemData>());

	List<CategoryData> listCatergory = new ArrayList<CategoryData>();

	private DrawerLayout mDrawerLayout;

	private ActionBarDrawerToggle mDrawerToggle;

	private CharSequence mDrawerTitle;
	private CharSequence mTitle;

	@StringArrayRes(R.array.user_setting)
	String[] usersetting;

	private CaldroidFragment dialogCaldroidFragment;

	private SimpleDateFormat dateFormat;

	private Date date;

	private Date formatedDate;

	Date lastSelectedDate = formatedDate;

	public void removeOrderItemData(OrderItemData orderItemData) {
		synchronized (orderItemDataList) {

			Iterator<OrderItemData> i = orderItemDataList.iterator();
			while (i.hasNext()) {
				OrderItemData orderItem = i.next();

				if (orderItem.getItemID().equals(orderItemData.getItemID())) {
					i.remove();
				}

			}
			afterDelete();

		}
	}

	public void updateOrderItemData(int selectQuentityValue,
			Double calculatedValue, Integer itemId) {
		synchronized (orderItemDataList) {

			Iterator<OrderItemData> i = orderItemDataList.iterator();
			while (i.hasNext()) {
				OrderItemData orderItem = i.next();

				if (orderItem.getItemID().equals(itemId)) {
					orderItem.setQuentity(selectQuentityValue);
					orderItem.setPrice(calculatedValue);
				}

			}
			totalPrice();

		}
	}

	@UiThread
	void afterDelete() {
		totalPrice();
		orderAdapater.notifyDataSetChanged();
		setListViewHeightBasedOnChildren(listViewItems);
		
		totalQuentiyCount();
	}

	void totalQuentiyCount() {
		int count = 0;
		for (OrderItemData orderItemData : orderItemDataList) {
			count += orderItemData.getQuentity();
		}

		setNotifCount(count);
	}

	@AfterViews
	void afterView() {

		BugSenseHandler.initAndStartSession(DrawerActivity.this,
				Constants.APIKEY);
		BugSenseHandler.startSession(DrawerActivity.this);

		

		setInfor(responceData);
		if (responceData != null
				&& responceData.getResponse().getTimes().size() > 0) {
			textViewTime.setText(responceData.getResponse().getTimes().get(0));
		}

		if (placeDataItemPar != null) {
			textViewMinimumOder.setText(placeDataItemPar.getMinorder());

		}

		if (userResonce != null) {
			textViewCreditMemo.setText(userResonce.getResponse()
					.getCreditMemo());
		}

		getCategory();

		for (String string : usersetting) {
			CategoryData cat = new CategoryData();
			cat.setTitle(string);

			listCatergory.add(cat);
		}

		dateFormat = new SimpleDateFormat(Constants.DATE_FOMAT);
		date = new Date();
		textViewDate.setText(dateFormat.format(date));
		try {
			formatedDate = dateFormat.parse(dateFormat.format(date));
		} catch (ParseException e) {
			//
			e.printStackTrace();
		}

		userAdapter.setCategoryData(listCatergory);
		userListView.setAdapter(userAdapter);
		setListViewHeightBasedOnChildren(userListView);

		mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

		mTitle = mDrawerTitle = getTitle();

		// set a custom shadow that overlays the main content when the drawer
		// opens
		mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
				GravityCompat.START);
		// enable ActionBar app icon to behave as action to toggle nav drawer
		getActionBar().setDisplayHomeAsUpEnabled(true);
		getActionBar().setHomeButtonEnabled(true);

		// ActionBarDrawerToggle ties together the the proper interactions
		// between the sliding drawer and the action bar app icon
		mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
		mDrawerLayout, /* DrawerLayout object */
		R.drawable.ic_navigation_drawer, /*
										 * nav drawer image to replace 'Up'
										 * caret
										 */
		R.string.drawer_open, /* "open drawer" description for accessibility */
		R.string.drawer_close /* "close drawer" description for accessibility */
		) {
			public void onDrawerClosed(View view) {
				getActionBar().setTitle(mTitle);
				invalidateOptionsMenu(); // creates call to
											// onPrepareOptionsMenu()
			}

			public void onDrawerOpened(View drawerView) {
				getActionBar().setTitle(mDrawerTitle);
				invalidateOptionsMenu(); // creates call to
											// onPrepareOptionsMenu()
			}
		};
		mDrawerLayout.setDrawerListener(mDrawerToggle);

		orderAdapater.setOnCallback(new OrderAdapater.Callback() {

			@Override
			public void onClicked(int selectQuentityValue,
					Double calculatedValue, Integer itemId) {
				updateOrderItemData(selectQuentityValue, calculatedValue,
						itemId);
			}

			@Override
			public void deleteFromCart(final OrderItemData orderItemData) {
				new Thread(new Runnable() {

					@Override
					public void run() {

						removeOrderItemData(orderItemData);

					}
				}).start();

			}
		});

		mDrawerLayout.openDrawer(leftDrawer);

	}

	// String price = "";

	Integer generator = 1;

	Map<Integer, ArrayList<GenarateItem>> generatorMap = new Hashtable<Integer, ArrayList<GenarateItem>>();

	Map<Integer, OrderItemData> orderItemDataMap = new Hashtable<Integer, OrderItemData>();

	private String creditmemo = "0.0";

	@Click({ R.id.textViewDate, R.id.textViewPaymentMethod, R.id.textViewTime,
			R.id.buttonCheckout, R.id.tel })
	void onClick(View view) {

		switch (view.getId()) {

		case R.id.tel:
			try {
				Intent callIntent = new Intent(Intent.ACTION_CALL);
				callIntent
						.setData(Uri.parse("tel:" + tel.getText().toString()));
				startActivity(callIntent);
			} catch (ActivityNotFoundException activityException) {
				Log.e(" dialer", "Call failed", activityException);
			}
			break;

		case R.id.textViewDate:

			dialogCaldroidFragment = new CaldroidFragment();
			dialogCaldroidFragment.setCaldroidListener(listener);

			Calendar cal = Calendar.getInstance();

			// Min date is last 7 days
			cal.add(Calendar.DATE, 0);
			Date minDate = cal.getTime();

			// Max date is next 7 days
			cal = Calendar.getInstance();
			cal.add(Calendar.DATE, 31);
			Date maxDate = cal.getTime();

			dialogCaldroidFragment.clearDisableDates();
			dialogCaldroidFragment.clearSelectedDates();

			dialogCaldroidFragment.setMinDate(minDate);
			dialogCaldroidFragment.setMaxDate(maxDate);

			dialogCaldroidFragment.refreshView();

			// If activity is recovered from rotation
			final String dialogTag = "CALDROID_DIALOG_FRAGMENT";
			if (state != null) {
				dialogCaldroidFragment.restoreDialogStatesFromKey(
						getSupportFragmentManager(), state,
						"DIALOG_CALDROID_SAVED_STATE", dialogTag);
				Bundle args = dialogCaldroidFragment.getArguments();
				if (args == null) {
					args = new Bundle();
					dialogCaldroidFragment.setArguments(args);
				}
				args.putString(CaldroidFragment.DIALOG_TITLE, "Select a date");
			} else {
				// Setup arguments
				Bundle bundle = new Bundle();
				// Setup dialogTitle
				bundle.putString(CaldroidFragment.DIALOG_TITLE, "Select a date");
				dialogCaldroidFragment.setArguments(bundle);
			}

			dialogCaldroidFragment.show(getSupportFragmentManager(), dialogTag);
			break;

		case R.id.textViewPaymentMethod:
			// System.out.println("textViewPaymentMethod");
			final CharSequence[] items = { "Cash", "Credit Cart" };
			AlertDialog.Builder builder = new AlertDialog.Builder(this,
					AlertDialog.THEME_HOLO_LIGHT);
			builder.setTitle("Select Payement Method");

			builder.setItems(items, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int item) {
					// Do something with the selection
					textViewPaymentMethod.setText(items[item]);
				}
			});
			AlertDialog alert = builder.create();
			// alert.getWindow().setBackgroundDrawableResource(
			// R.color.caldroid_white);
			alert.show();
			break;

		case R.id.textViewTime:
			// final CharSequence[] items = { "Cash", "Credit Cart" };

			List<CharSequence> timesList = responceData.getResponse()
					.getTimes();

			final CharSequence[] array = timesList.toArray(new String[timesList
					.size()]);

			for (CharSequence charSequence : array) {
				System.out.println(charSequence);
			}

			AlertDialog.Builder builderTime = new AlertDialog.Builder(this,
					AlertDialog.THEME_HOLO_LIGHT);
			builderTime.setTitle("Select Time");
			builderTime.setItems(array, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int item) {
					// Do something with the selection
					textViewTime.setText(array[item]);
				}
			});
			AlertDialog alertTime = builderTime.create();
			// alertTime.getWindow().setBackgroundDrawableResource(
			// R.color.caldroid_white);
			alertTime.show();
			break;
		case R.id.buttonCheckout:
			if (userResonce == null) {
				openDialog();
			} else {
				DialogFragment newFragment = new FireMissilesDialogFragment();
				newFragment.show(getSupportFragmentManager(), "Order");

			}
			break;

		default:
			break;
		}
	}

	private void openDialog() {
		final Dialog dialog = new Dialog(DrawerActivity.this);
		dialog.setTitle("login");
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.login_drawer);
		dialog.getWindow().setBackgroundDrawable(
				new ColorDrawable(android.graphics.Color.TRANSPARENT));
		dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;

		dialog.getWindow().setGravity(Gravity.BOTTOM);
		Button btnDismiss = (Button) dialog.getWindow().findViewById(
				R.id.cancelButton);

		Button loginButton = (Button) dialog.getWindow().findViewById(
				R.id.loginButton);

		Button registerButton = (Button) dialog.getWindow().findViewById(
				R.id.registerButton);

		registerButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent intent = new Intent(DrawerActivity.this,
						SignUpFromDraweActivity_.class);

				startActivityForResult(intent, LOGIN);
				dialog.dismiss();
				overridePendingTransition(R.anim.open_next, R.anim.close_main);

			}
		});

		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent intent = new Intent(DrawerActivity.this,
						LoginFromDrawerActivity_.class);

				// if (responceDataParce != null) {
				// intent.putExtra("ResponceData", responceDataParce);
				//
				// }

				// startActivity(intent);
				dialog.dismiss();
				startActivityForResult(intent, LOGIN);

				overridePendingTransition(R.anim.open_next, R.anim.close_main);

			}
		});

		btnDismiss.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});

		dialog.show();
	}

	public class FireMissilesDialogFragment extends DialogFragment {
		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState) {
			// Use the Builder class for convenient dialog construction
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			builder.setMessage("By submitting the order you accept our T & Cs")
					.setPositiveButton("Ok",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									// FIRE ZE MISSILES!

									if (Double.parseDouble(placeDataItemPar
											.getMinorder()) < totalPrice) {
										checkOut(userResonce,
												orderItemDataList, generatorMap);
									} else {
										showMessge("Oder less than minimum order");
									}
								}
							})
					.setNegativeButton("Cancel",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									// User cancelled the dialog
									dialog.dismiss();
								}
							});
			// Create the AlertDialog object and return it
			return builder.create();
		}
	}

	@UiThread
	void totalPrice() {
		Double totlPrice = 0.0;

		for (OrderItemData orderItemData : orderItemDataList) {
			totlPrice += orderItemData.getPrice();
		}
		if (userResonce != null) {
			creditmemo = userResonce.getResponse().getCreditMemo();
		}
		totalPrice = totlPrice - Double.parseDouble(creditmemo);
		textViewTotal.setText(totalPrice.toString());
		
		totalQuentiyCount();

	}

	MultiValueMap<String, String> mvMap = new LinkedMultiValueMap<String, String>();

	void checkOut(UserResonce userResonce2,
			List<OrderItemData> orderItemDataList2,
			Map<Integer, ArrayList<GenarateItem>> generatorMap2) {

		SimpleDateFormat smD = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat smT = new SimpleDateFormat("HH:mm:ss");

		Date dateForCheckout = new Date();

		mvMap.add("type", "12");

		mvMap.add("date", smD.format(dateForCheckout));

		mvMap.add("time", smT.format(dateForCheckout));

		mvMap.add("cart_items_count", String.valueOf(orderItemDataList2.size()));

		mvMap.add("deliverdate", textViewDate.getText().toString());

		mvMap.add("delivertime", textViewTime.getText().toString());

		SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");
		
		
		Calendar calendar = Calendar.getInstance();
        //MultiValueMap multivaluemap;
        String s;
        if (calendar.get(Calendar.DAY_OF_WEEK) == 1)
        {
            mvMap.add("deliverday", "7");
        } else
        {
            mvMap.add("deliverday", String.valueOf(-1 + calendar.get(Calendar.DAY_OF_WEEK)));
        }

//		mvMap.add("deliverday", datesMap
//				.get(dateFormat.format(dateForCheckout)).toString());

		GregorianCalendar cal = new GregorianCalendar();

		mvMap.add("timestamp", String.valueOf(cal.getTimeInMillis()));

		mvMap.add("note", "note");

		mvMap.add("ordertotal", textViewTotal.getText().toString());

		// System.out.println("ss" + cal.getTimeInMillis());

		mvMap.add("paymentmethod", textViewPaymentMethod.getText().toString());

		mvMap.add("status", "Pending");

		UserData user = userResonce2.getResponse();

		mvMap.add("user_registered",
				user.getCustomerID().isEmpty() ? "Unregistered" : "Registered");

		mvMap.add("user", user.getEMail());

		mvMap.add("email", user.getEMail());

		mvMap.add("firstname", user.getFirstName());

		mvMap.add("lastname", user.getLastName());

		mvMap.add("no", user.getHouseNr());

		mvMap.add("city", user.getCity());

		mvMap.add("company", user.getCompany());

		mvMap.add("street", user.getStreet());

		mvMap.add("tel", user.getPhoneNo());

		mvMap.add("zip", user.getPlz());

		mvMap.add("device_token", "GCM");

		mvMap.add("street", user.getStreet());

		mvMap.add("tel", user.getPhoneNo());

		mvMap.add("device_type", "android");

		// int generatedItem = 0;
		//
		// int withoutsize = 0;
		//
		// int withsize = 0;

		int counter = 1;

		int generatorIndex = 0;

		for (OrderItemData orderItemData : orderItemDataList2) {
			System.out.println("orderItemData " + orderItemData.getTitle());

			if (orderItemData.getType().equals(GENERATED_PIZZA)) {

				// quntiti * price cuz getprice

				ArrayList<GenarateItem> items = generatorMap2.get(orderItemData
						.getItemID());

				for (GenarateItem genarateItem : items) {

					System.out.println("generatorIndex " + generatorIndex
							+ " name " + genarateItem.getTitle());

					generatorIndex++;

					mvMap.add("cart_generated_date" + generatorIndex,
							textViewDate.getText().toString());

					mvMap.add("cart_generated_ip" + generatorIndex,
							getIPAddress(true)); // model

					mvMap.add("cart_generated_itemname" + generatorIndex,
							genarateItem.getTitle());

					mvMap.add("cart_generated_itemid" + generatorIndex,
							genarateItem.getItemID());

					mvMap.add("cart_generated_number" + generatorIndex,
							orderItemData.getItemID().toString());

					mvMap.add("cart_generated_price" + generatorIndex,
							genarateItem.getPrice());

					mvMap.add("cart_generated_qty" + generatorIndex, "1");

					mvMap.add("cart_generated_ref" + generatorIndex,
							orderItemData.getRefID());

					mvMap.add("cart_generated_status" + generatorIndex,
							"Pending");

					mvMap.add("cart_generated_time" + generatorIndex,
							smT.format(dateForCheckout));

					mvMap.add("cart_generated_timestamp" + generatorIndex,
							String.valueOf(cal.getTimeInMillis()));

					mvMap.add("cart_generated_type" + generatorIndex, "Zutaten");

				}// end of loop sub items

				System.out.println("edn of loop" + mvMap);

				System.out.println("generatorIndex " + generatorIndex);

				generatorIndex++;

				System.out.println("generatorIndex + " + generatorIndex);

				mvMap.add("cart_generated_date" + generatorIndex, textViewDate
						.getText().toString());

				mvMap.add("cart_generated_ip" + generatorIndex,
						getIPAddress(true)); // model

				mvMap.add("cart_generated_itemname" + generatorIndex,
						orderItemData.getSize());

				mvMap.add("cart_generated_itemid" + generatorIndex,
						orderItemData.getItemID().toString());

				mvMap.add("cart_generated_number" + generatorIndex,
						orderItemData.getItemID().toString());

				mvMap.add("cart_generated_price" + generatorIndex,
						orderItemData.getItemPrice().toString());

				mvMap.add("cart_generated_qty" + generatorIndex, "1");

				// mvMap.add("cart_generated_price" + generatorIndex,
				// orderItemData.getItemPrice().toString());

				mvMap.add("cart_generated_ref" + generatorIndex,
						orderItemData.getRefID());

				mvMap.add("cart_generated_status" + generatorIndex, "Pending");

				mvMap.add("cart_generated_time" + generatorIndex,
						smT.format(dateForCheckout));

				mvMap.add("art_generated_timestamp" + generatorIndex,
						String.valueOf(cal.getTimeInMillis()));

				mvMap.add("cart_generated_type" + generatorIndex, "Brot");

				// main item

				mvMap.add("cart_items_amount" + counter, orderItemData
						.getPrice().toString());

				mvMap.add("cart_items_date" + counter, textViewDate.getText()
						.toString());

				mvMap.add("cart_items_ip" + counter, getIPAddress(true)); // get
																			// device
																			// id

				mvMap.add("cart_items_itemname" + counter,
						orderItemData.getTitle() + " ("+orderItemData.getSize()+" )");

				mvMap.add("cart_items_itemref" + counter, orderItemData
						.getItemID().toString());

				mvMap.add("cart_items_itemsize" + counter,
						orderItemData.getSize());

				mvMap.add("cart_items_itemtype" + counter, "Generated");

				mvMap.add("cart_items_qty" + counter, orderItemData
						.getQuentity().toString());

				mvMap.add("cart_items_ref" + counter, orderItemData.getRefID()); //

				mvMap.add("cart_items_status" + counter, "Pending");

				mvMap.add("cart_items_time" + counter, textViewTime.getText()
						.toString());

				mvMap.add("cart_items_timestamp" + counter,
						String.valueOf(cal.getTimeInMillis()));

				mvMap.add("cart_items_unitprice" + counter, orderItemData
						.getItemPrice().toString());// test

				mvMap.add("cart_items_user" + counter, user.getEMail());

			}

			if (orderItemData.getType().equals(WITH_OUT_SIZE)) {

				mvMap.add("cart_items_amount" + counter, orderItemData
						.getPrice().toString());

				mvMap.add("cart_items_date" + counter, textViewDate.getText()
						.toString());

				mvMap.add("cart_items_ip" + counter, getIPAddress(true)); // get
																			// device
																			// id

				mvMap.add("cart_items_itemname" + counter,
						orderItemData.getTitle());

				mvMap.add("cart_items_itemref" + counter,
						orderItemData.getItemID() + orderItemData.getTitle());

				mvMap.add("cart_items_itemsize" + counter, "1");

				mvMap.add("cart_items_itemtype" + counter, "Product");

				mvMap.add("cart_items_qty" + counter, orderItemData
						.getQuentity().toString());

				mvMap.add("cart_items_ref" + counter, orderItemData.getItemID()
						+ orderItemData.getTitle()); //

				mvMap.add("cart_items_status" + counter, "Pending");

				mvMap.add("cart_items_time" + counter, textViewTime.getText()
						.toString());

				mvMap.add("cart_items_timestamp" + counter,
						String.valueOf(cal.getTimeInMillis()));

				mvMap.add("cart_items_unitprice" + counter, orderItemData
						.getItemPrice().toString());

				mvMap.add("cart_items_user" + counter, user.getEMail());

			}

			if (orderItemData.getType().equals(WITH_SIZE)) {

				mvMap.add("cart_items_amount" + counter, orderItemData
						.getPrice().toString());

				mvMap.add("cart_items_date" + counter, textViewDate.getText()
						.toString());

				mvMap.add("cart_items_ip" + counter, getIPAddress(true)); // get
																			// device
																			// id

				mvMap.add("cart_items_itemname" + counter,
						orderItemData.getTitle());

				mvMap.add("cart_items_itemref" + counter, orderItemData
						.getItemID().toString());

				mvMap.add("cart_items_itemsize" + counter,
						orderItemData.getSize());

				mvMap.add("cart_items_itemtype" + counter, "Product");

				mvMap.add("cart_items_qty" + counter, orderItemData
						.getQuentity().toString());

				mvMap.add("cart_items_ref" + counter, orderItemData.getItemID()
						+ orderItemData.getTitle()); //

				mvMap.add("cart_items_status" + counter, "Pending");

				mvMap.add("cart_items_time" + counter, textViewTime.getText()
						.toString());

				mvMap.add("cart_items_timestamp" + counter,
						String.valueOf(cal.getTimeInMillis()));

				mvMap.add("cart_items_unitprice" + counter, orderItemData
						.getItemPrice().toString());

				mvMap.add("cart_items_user" + counter, user.getEMail());
			}

			counter++;
		}

		mvMap.add("cart_generated_count", String.valueOf(generatorIndex));
		generatorIndex = 0;
		counter = 1;

		System.out.println("String.valueOf(generatorIndex) "
				+ String.valueOf(generatorIndex));

		System.out.println(mvMap.toString());

		doCheckot(mvMap);

	}

	@Background
	void doCheckot(final MultiValueMap<String, String> mvMap) {
		new ReachabilityTest(DrawerActivity.this,
				new ReachabilityTest.Callback() {

					@Override
					public void onReachabilityTestPassed() {

						try {
							uiDoCheckOut(InfoClient.checkOut(mvMap));
						} catch (Exception e) {

							System.err.println(e);
						}
					}

					@Override
					public void onReachabilityTestFailed() {

						showMessge("Not connected ");
					}
				});
	}

	// @UiThread
	// void uiDoCheckOut(String string) {
	// mvMap.clear();
	//
	// Log.d("test", string);
	// // if (string.getResponse().getStatus().equals("1")) {
	// // showMessge(string.getResponse().getMessage());
	// // DrawerActivity.this.finish();
	// // }
	//
	// }

	@UiThread
	void uiDoCheckOut(OderResponce oderResponce) {
		mvMap.clear();
		if (oderResponce.getResponse().getStatus().equals(1)) {
			showMessge(oderResponce.getResponse().getMessage());
			DrawerActivity.this.finish();
		}

	}

	/**
	 * Get IP address from first non-localhost interface
	 * 
	 * @param ipv4
	 *            true=return ipv4, false=return ipv6
	 * @return address or empty string
	 */
	public static String getIPAddress(boolean useIPv4) {
		try {
			List<NetworkInterface> interfaces = Collections
					.list(NetworkInterface.getNetworkInterfaces());
			for (NetworkInterface intf : interfaces) {
				List<InetAddress> addrs = Collections.list(intf
						.getInetAddresses());
				for (InetAddress addr : addrs) {
					if (!addr.isLoopbackAddress()) {
						String sAddr = addr.getHostAddress().toUpperCase();
						boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
						if (useIPv4) {
							if (isIPv4)
								return sAddr;
						} else {
							if (!isIPv4) {
								int delim = sAddr.indexOf('%'); // drop ip6 port
																// suffix
								return delim < 0 ? sAddr : sAddr.substring(0,
										delim);
							}
						}
					}
				}
			}
		} catch (Exception ex) {
		} // for now eat exceptions
		return "";
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// Check which request we're responding to
		// System.out.println("resultCode" + resultCode);
		//
		// System.out.println("requestCode" + requestCode);

		if (requestCode == LOGIN) {
			// Make sure the request was successful
			if (resultCode == Activity.RESULT_OK) {
				// The user picked a contact.
				// The Intent's data Uri identifies which contact was selected.

				// Do something with the contact here (bigger example below)

				if (data != null) {
					Bundle extra = data.getExtras();

					UserResonce userResonceData = extra
							.getParcelable("UserResonce");

					System.out.println("UserResonce"
							+ userResonceData.getResponse().getFirstName());

					showMessge("username "
							+ userResonceData.getResponse().getFirstName());

					userResonce = userResonceData;

					if (userResonce != null) {
						textViewCreditMemo.setText(userResonceData
								.getResponse().getCreditMemo());

						checkOut(userResonce, orderItemDataList, generatorMap);
					}
				}

			}
		}
	}

	static final int LOGIN = 2; // The request code

	private static final int GENERATED_PIZZA = 3;

	private static final int WITH_OUT_SIZE = 2;

	private static final int WITH_SIZE = 1;

	@ItemClick({ R.id.userListView })
	void itemClick(CategoryData categoryData) {
		// System.out.println("w" + categoryData.getTitle());

		if (categoryData.getTitle().equals("Delivery Location")) {

			final FragmentTransaction transaction = getSupportFragmentManager()
					.beginTransaction();

			PlaceFragment placefragment = PlaceFragment.newInstance(
					responceData, userResonce);
			placefragment.setOnCallback(new PlaceFragment.Callback() {

				@Override
				public void clickPlace(PlaceData placeDataItem) {
					// TODO Auto-generated method stub
					placeDataItemPar = placeDataItem;
					pizzWithSizeFagment(categoryDataFirst);
				}
			});

			transaction.replace(R.id.container, placefragment);
			transaction.addToBackStack(null);
			transaction.commit();
			mDrawerLayout.closeDrawer(leftDrawer);
		}

		if (categoryData.getTitle().equals("Notifcation")) {
			NotificationFragment fragment = new NotificationFragment_();

			final FragmentTransaction transaction = getSupportFragmentManager()
					.beginTransaction();
			transaction.replace(R.id.container, fragment);
			transaction.addToBackStack(null);
			transaction.commit();
			mDrawerLayout.closeDrawer(leftDrawer);
		}

		if (categoryData.getTitle().equals("Home")) {
			DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					switch (which) {
					case DialogInterface.BUTTON_POSITIVE:
						// Yes button clicked
						DrawerActivity.this.finish();
						break;

					case DialogInterface.BUTTON_NEGATIVE:
						// No button clicked
						dialog.dismiss();
						break;
					}
				}
			};

			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("Are you sure?")
					.setPositiveButton("Yes", dialogClickListener)
					.setNegativeButton("No", dialogClickListener).show();
		}
	}

	@ItemClick(R.id.categoryListView)
	void onItemCategoryClick(CategoryData categoryData) {
		// System.out.println("categoryData" + categoryData.getTitle());

		getActionBar().setTitle(categoryData.getTitle());

		int category = Integer.parseInt(categoryData.getCategorytype());

		switch (category) {
		case GENERATED_PIZZA:

			pizaGeneratorFragment(categoryData);

			break;

		case WITH_OUT_SIZE:

			pizzWithOutSizeFragemnt(categoryData);

			break;
		case WITH_SIZE:
			pizzWithSizeFagment(categoryData);
			break;
		default:
			break;
		}

		mDrawerLayout.closeDrawer(leftDrawer);
	}

	private void pizaGeneratorFragment(CategoryData categoryData) {
		PizzaGenaratorFragment fragment = PizzaGenaratorFragment
				.newInstance(categoryData);

		fragment.setmCallback(new SelectCallCallBack() {

			@Override
			public void onClicked(ArrayList<GenarateItem> selectedItems,
					Size bunSizePrice) {

				Double calculatedPrice = 0.0;

				int randomNum = 1000 + (int) (Math.random() * 9999);

				System.out.println("randomNum" + randomNum);

				for (GenarateItem genarateItem : selectedItems) {
					// System.out.println("onclick" + genarateItem);

					calculatedPrice += Double.parseDouble(genarateItem
							.getPrice());
				}

				calculatedPrice += Double.parseDouble(bunSizePrice.getPrice());
				// textViewTotal.setText(price);

				OrderItemData orderItemData = new OrderItemData();

				orderItemData.setRefID(String.valueOf(randomNum));
				orderItemData.setType(GENERATED_PIZZA);
				orderItemData.setItemID(randomNum);
				orderItemData.setTitle("Generator item " + generator++);
				orderItemData.setQuentity(1);
				orderItemData.setSize(bunSizePrice.getSize());

				orderItemData.setItemPrice(Double.valueOf(bunSizePrice
						.getPrice()));

				orderItemData.setPrice(calculatedPrice);

				generatorMap.put(randomNum, selectedItems);

				// generator++;

				orderItemDataList.add(orderItemData);

				orderAdapater.setOrderItemList(orderItemDataList);

				listViewItems.setAdapter(orderAdapater);

				// listViewItems.invalidateViews();

				orderAdapater.notifyDataSetChanged();

				setListViewHeightBasedOnChildren(listViewItems);

				calculatedPrice = 0.0;

				mDrawerLayout.openDrawer(rightDrawer);

				// textViewtest.setText(selectedItems.size());
				totalPrice();

				mDrawerLayout.closeDrawer(leftDrawer);
				
				totalQuentiyCount();

			}

		});

		getSupportFragmentManager().beginTransaction()
				.replace(R.id.container, fragment).commit();
	}

	private void pizzWithOutSizeFragemnt(CategoryData categoryData) {
		PizzaWithoutSizeFragment pizzaFragment = PizzaWithoutSizeFragment
				.newInstance(categoryData, placeDataItemPar);

		pizzaFragment.setOnCallback(new PizzaWithoutSizeFragment.Callback() {

			@Override
			public void addToCart(GenarateItem genarateItem) {

				OrderItemData orderItemData = new OrderItemData();
				orderItemData.setType(WITH_OUT_SIZE);
				orderItemData.setItemID(Integer.parseInt(genarateItem
						.getItemID()));
				orderItemData.setTitle(genarateItem.getTitle());
				orderItemData.setQuentity(genarateItem.getQuentity());
				orderItemData.setSize("");

				orderItemData.setItemPrice(Double.valueOf(genarateItem
						.getPrice()));

				if (genarateItem.getCalculatedValue() == 0.0) {
					orderItemData.setPrice(Double.valueOf(genarateItem
							.getPrice()));

				} else {
					orderItemData.setPrice(genarateItem.getCalculatedValue());
				}

				Boolean isExist = false;

				for (OrderItemData orderItemDataLoop : orderItemDataList) {
					if (orderItemDataLoop.getItemID().equals(
							orderItemData.getItemID())) {

						orderItemDataLoop.setQuentity(orderItemDataLoop
								.getQuentity() + genarateItem.getQuentity());

						Double price = orderItemDataLoop.getQuentity()
								* Double.valueOf(genarateItem.getPrice());

						orderItemDataLoop.setPrice(price);
						isExist = true;
						break;
					}
				}

				if (!isExist) {

					orderItemDataList.add(orderItemData);
				}

				orderAdapater.setOrderItemList(orderItemDataList);

				listViewItems.setAdapter(orderAdapater);

				// listViewItems.invalidateViews();

				orderAdapater.notifyDataSetChanged();

				setListViewHeightBasedOnChildren(listViewItems);
				mDrawerLayout.openDrawer(rightDrawer);
				totalPrice();
				mDrawerLayout.closeDrawer(leftDrawer);
				
				totalQuentiyCount();
			}
		});

		getSupportFragmentManager().beginTransaction()
				.replace(R.id.container, pizzaFragment).commit();

	}

	private void pizzWithSizeFagment(CategoryData categoryData) {
		PizzaWithSizeFragment pizzaWithSizeFragment = PizzaWithSizeFragment
				.newInstance(categoryData, placeDataItemPar);

		pizzaWithSizeFragment
				.setOnCallback(new PizzaWithSizeFragment.Callback() {

					@Override
					public void addToCart(GenarateItem genarateItem) {

						OrderItemData orderItemData = new OrderItemData();
						orderItemData.setType(WITH_SIZE);
						orderItemData.setItemID(Integer.parseInt(genarateItem
								.getItemID()));
						orderItemData.setTitle(genarateItem.getTitle());
						orderItemData.setQuentity(genarateItem.getQuentity());

						orderItemData.setSize(genarateItem.getSizes()
								.get(genarateItem.getSelectedSizeIndex())
								.getSize());

						if (genarateItem.getCalculatedValue() == 0.0) {
							orderItemData.setPrice(Double.valueOf(genarateItem
									.getSizes()
									.get(genarateItem.getSelectedSizeIndex())
									.getPrices().getPrice()));
						} else {
							orderItemData.setPrice(genarateItem
									.getCalculatedValue());
						}

						orderItemData.setItemPrice(Double.valueOf(genarateItem
								.getSizes()
								.get(genarateItem.getSelectedSizeIndex())
								.getPrices().getPrice()));
						// orderItemDataList.add(orderItemData);

						Boolean isExist = false;

						for (OrderItemData orderItemDataLoop : orderItemDataList) {
							if ((orderItemDataLoop.getItemID() == orderItemData
									.getItemID())
									&& orderItemDataLoop.getSize().equals(
											orderItemData.getSize())) {

								orderItemDataLoop.setQuentity(orderItemDataLoop
										.getQuentity()
										+ genarateItem.getQuentity());

								Double price = orderItemDataLoop.getQuentity()
										* orderItemDataLoop.getItemPrice();

								orderItemDataLoop.setPrice(price);
								isExist = true;
								break;
							}
						}

						if (!isExist) {

							orderItemDataList.add(orderItemData);
						}

						orderAdapater.setOrderItemList(orderItemDataList);

						listViewItems.setAdapter(orderAdapater);

						orderAdapater.notifyDataSetChanged();

						setListViewHeightBasedOnChildren(listViewItems);

						mDrawerLayout.openDrawer(rightDrawer);

						totalPrice();
						mDrawerLayout.closeDrawer(leftDrawer);
						
						totalQuentiyCount();
					}
				});

		getSupportFragmentManager().beginTransaction()
				.replace(R.id.container, pizzaWithSizeFragment).commit();
	}

	@Background
	void getCategory() {

		SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();

		SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");

		infoDto.setDate(sm.format(date));
		infoDto.setDay(dateFormat.format(date));
		infoDto.setType("4");

		new ReachabilityTest(DrawerActivity.this,
				new ReachabilityTest.Callback() {

					@Override
					public void onReachabilityTestPassed() {

						try {
							setCategory(InfoClient.getCatergory(infoDto
									.getMultiValuedMap()));
						} catch (Exception e) {
							showProgress(false);
							System.err.println(e);
						}
					}

					@Override
					public void onReachabilityTestFailed() {
						showProgress(false);
						showMessge("Not connected ");
					}
				});
	}

	CategoryData categoryDataFirst;

	@UiThread
	void setCategory(CategoryResponceData catergory) {
		showProgress(false);
		List<CategoryData> categoryList = catergory.getResponse()
				.getCategoryDataList();
		if (categoryList != null) {
			categoryAdapter.setCategoryData(categoryList);
			categoryListView.setAdapter(categoryAdapter);
			setListViewHeightBasedOnChildren(categoryListView);
			if (categoryList.size() > 0) {

				for (CategoryData categoryData : categoryList) {
					System.out.println("test" + categoryData.getCatID());
					if (categoryData.getCatID().equals("5")) {

						categoryDataFirst = categoryData;
						pizzWithSizeFagment(categoryDataFirst);
						break;
					}
				}

			}
		}

	}

	@UiThread
	void showMessge(final String msg) {
		Toast.makeText(DrawerActivity.this, msg, Toast.LENGTH_LONG).show();
	}

	@UiThread
	void setInfor(final ResponceData responceData) {
		if (progressBarTime.getVisibility() == View.VISIBLE) {
			progressBarTime.setVisibility(View.INVISIBLE);
			textViewTime.setVisibility(View.VISIBLE);
		}

		if (responceData != null
				&& responceData.getResponse().getTimes().size() > 0) {
			textViewTime.setText(responceData.getResponse().getTimes().get(0));
		}
		if (responceData != null) {
			InfoData infoData = responceData.getResponse();
			String address1 = infoData.getAddress1() + " "
					+ infoData.getAddress2() + ", " + infoData.getZip() + ", "
					+ infoData.getCity();

			address1tv.setText("" + address1);
			opentime.setText("" + infoData.getOpentime());

			tel.setText("" + infoData.getTel());

		}

	}

	@Trace
	public void setListViewHeightBasedOnChildren(ListView listView) {
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null)
			return;

		int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
				MeasureSpec.UNSPECIFIED);
		int totalHeight = 0;
		View view = null;
		for (int i = 0; i < listAdapter.getCount(); i++) {
			view = listAdapter.getView(i, view, listView);
			if (i == 0)
				view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth,
						LayoutParams.WRAP_CONTENT));

			view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
			totalHeight += view.getMeasuredHeight();
		}
		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight
				+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		listView.setLayoutParams(params);
		listView.requestLayout();
	}

	static Button notifCount;
	static int mNotifCount = 0;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		MenuItem item = menu.findItem(R.id.menu_item_share);

		MenuItemCompat.setActionView(item, R.layout.feed_update_count);

		notifCount = (Button) MenuItemCompat.getActionView(item);

		notifCount.setText(String.valueOf(mNotifCount));
		return super.onCreateOptionsMenu(menu);
	}

	private void setNotifCount(int count) {
		mNotifCount = count;
		invalidateOptionsMenu();
	}

	/* Called whenever we call invalidateOptionsMenu() */
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {

		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// The action bar home/up action should open or close the drawer.
		// ActionBarDrawerToggle will take care of this.
		if (mDrawerToggle.onOptionsItemSelected(item)) {
			return true;
		}

		switch (item.getItemId()) {
		case R.id.menu_item_share:

			if (mDrawerLayout.isDrawerOpen(leftDrawer)) {
				mDrawerLayout.closeDrawer(leftDrawer);
			}

			if (mDrawerLayout.isDrawerOpen(rightDrawer)) {
				mDrawerLayout.closeDrawer(rightDrawer);
			} else {
				mDrawerLayout.openDrawer(rightDrawer);
			}
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}

	}

	@Override
	public void setTitle(CharSequence title) {
		mTitle = title;
		getActionBar().setTitle(mTitle);
	}

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		// Sync the toggle state after onRestoreInstanceState has occurred.
		mDrawerToggle.syncState();
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
		// Pass any configuration change to the drawer toggls
		mDrawerToggle.onConfigurationChanged(newConfig);
	}

	private Bundle state;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		state = savedInstanceState;
	}

	@Background
	void getInfo() {

		//SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");

		SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();

		infoDtoNew.setDate(sm.format(date));

		// infoDtoNew.setDate("2014-02-25");
		Calendar calendar = Calendar.getInstance();
        if (calendar.get(Calendar.DAY_OF_WEEK) == 1)
        {
            infoDtoNew.setDay("7");
        } else
        {
            infoDtoNew.setDay(String.valueOf(-1 + calendar.get(Calendar.DAY_OF_WEEK)));
        }
		infoDto.setType("11");

		new ReachabilityTest(DrawerActivity.this,
				new ReachabilityTest.Callback() {

					@Override
					public void onReachabilityTestPassed() {

						try {
							setInfor(InfoClient.getInfo(infoDto
									.getMultiValuedMap()));
						} catch (Exception e) {

							System.err.println(e);
						}
					}

					@Override
					public void onReachabilityTestFailed() {

						showMessge("Not connected ");
					}
				});
	}

	@ViewById(R.id.progressBarTime)
	ProgressBar progressBarTime;

	final CaldroidListener listener = new CaldroidListener() {

		@Override
		public void onSelectDate(Date datenew, View view) {

			textViewDate.setText(dateFormat.format(datenew));
			dialogCaldroidFragment.dismiss();

			try {
				lastSelectedDate = dateFormat.parse(dateFormat.format(date));
			} catch (ParseException e) {

				e.printStackTrace();
			}

			if (lastSelectedDate.compareTo(datenew) < 0) {
				if (progressBarTime.getVisibility() == View.INVISIBLE) {
					progressBarTime.setVisibility(View.VISIBLE);
					textViewTime.setVisibility(View.INVISIBLE);
				}
				getInfoOnDate(datenew);
			}

		}

		@Override
		public void onChangeMonth(int month, int year) {

		}

		@Override
		public void onLongClickDate(Date date, View view) {

		}

		@Override
		public void onCaldroidViewCreated() {

		}

	};

	//Map<String, Integer> datesMap = new HashMap<String, Integer>();

	@Bean
	InfoDto infoDtoNew;
	@RestService
	InfoClient infoClient;

	@Background
	void getInfoOnDate(Date datenew) {

		SimpleDateFormat dateFormat = new SimpleDateFormat("EEE");

		SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();

		infoDtoNew.setDate(sm.format(date));

		// infoDtoNew.setDate("2014-02-25");
		Calendar calendar = Calendar.getInstance();
        if (calendar.get(Calendar.DAY_OF_WEEK) == 1)
        {
            infoDtoNew.setDay("7");
        } else
        {
            infoDtoNew.setDay(String.valueOf(-1 + calendar.get(Calendar.DAY_OF_WEEK)));
        }
		infoDtoNew.setType("11");

		new ReachabilityTest(DrawerActivity.this,
				new ReachabilityTest.Callback() {

					@Override
					public void onReachabilityTestPassed() {

						try {
							setInfor(infoClient.getInfo(infoDtoNew
									.getMultiValuedMap()));
						} catch (Exception e) {

							System.err.println(e);
						}
					}

					@Override
					public void onReachabilityTestFailed() {
						showProgress(false);
						showMessge("Not connected ");
					}
				});
	}

	@UiThread
	void showProgress(final boolean show) {
		mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
		categoryListView.setVisibility(show ? View.GONE : View.VISIBLE);
	}

}
